//
//  SCACoinView.swift
//  SCA
//
//  Created by tjun on 2025/9/5.
//

import UIKit

 
class SCACoinView: UIView {

    private let iconImageView = UIImageView()
    private let trendImageView = UIImageView(image: UIImage(named: "green_arrow"))
    
    private let iconNameLabel = UILabel(font: UIFontSemiboldMake(16), textColor: .white)
    private let priceLabel = UILabel(font: UIFontSemiboldMake(16), textColor: .white)
    private let increaseValueLabel = UILabel(font: UIFontSemiboldMake(13), textColor: .green)
    
    var model: SCAModel? {
        didSet {
            iconImageView.setImage(url: model?.icon)
            iconNameLabel.text = model?.title
            priceLabel.text = model?.price
            increaseValueLabel.text = model?.percent_disp
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setSubView()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setSubView() {
        
        backgroundColor = AppStyle.color.background
        
        addSubviews(iconImageView, iconNameLabel, priceLabel, trendImageView, increaseValueLabel)
        iconImageView.snp.makeConstraints { make in
            make.left.equalTo(20)
            make.centerY.equalToSuperview()
            make.width.height.equalTo(40)
        }
        
        iconNameLabel.snp.makeConstraints { make in
            make.left.equalTo(iconImageView.snp.right).offset(14)
            make.centerY.equalTo(iconImageView)
        }
        
        priceLabel.snp.makeConstraints { make in
            make.right.equalTo(-50)
            make.top.equalTo(iconImageView)
        }
 
        increaseValueLabel.snp.makeConstraints { make in
            make.right.equalTo(priceLabel)
            make.bottom.equalTo(iconImageView)
        }
        
        trendImageView.snp.makeConstraints { make in
            make.right.equalTo(increaseValueLabel.snp.left).offset(-6)
            make.centerY.equalTo(increaseValueLabel)
        }
        
        let arrowImageView = UIImageView(image: UIImage(named: "arrow_icon")).addTo(self)
        arrowImageView.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.right.equalTo(-20)
        }
    }

}
